package main

import (
	"fmt"
	"strconv"
	"time"
)

type ListItem struct {
	Id     int    `json:"id,omitempty"`
	Rank   int    `json:"rank,omitempty"`
	Name   string `json:"name,omitempty"`
	Symbol string `json:"symbol,omitempty"`
	slug   string `json:"slug,omitempty"`
}

func NewListItem() *ListItem {
	return &ListItem{}
}

type RateData struct {
	Id   int     `json:"id,omitempty"`
	Name string  `json:"name,omitempty"`
	Rate float64 `json:"rate"`
	time string  `json:"time"'`
}

func NewRateData(id int, name string, rate float64, time time.Time) *RateData {
	return &RateData{Id: id, Name: name, Rate: rate, time: FormartTime(time)}
}

type Step2Data struct {
	T    time.Time
	Data map[int]Item
}

type RankPair struct {
	Index int
	Left  float64
	Right float64
	Value int
	time  string
}

func NewRankPair(index int, left float64, right float64, value int, time string) *RankPair {
	return &RankPair{Index: index, Left: left, Right: right, Value: value, time: time}
}

func (rp *RankPair) InRank(v float64) bool {
	//左闭右开
	//1 - 6
	//-1 -6
	if rp.Left >= 0 && rp.Right >= 0 {
		if rp.Left <= v && v < rp.Right {
			rp.Value = rp.Value + 1
			return true
		}
	} else {
		if rp.Right < v && v <= rp.Left {
			rp.Value = rp.Value + 1

			return true
		}
	}

	return false
}
func (rp *RankPair) isInRank(v float64) bool {
	//左闭右开
	return rp.Left <= v && v < rp.Right
}

type Row struct {
	TimeKey string
	Index   int
	Right   int
	Left    int
}

func NewRow(timeKey string, index int, right int, left int) *Row {
	return &Row{TimeKey: timeKey, Index: index, Right: right, Left: left}
}

type ExcelPair struct {
	Key   float64
	Value int
}

func NewExcelPair(key float64, value int) *ExcelPair {
	t, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", key), 64)
	return &ExcelPair{Key: t, Value: value}
}

type ChartPair struct {
	Key   string
	Value float64
	Time  string
}

func NewChartPair(key string, value float64, time string) *ChartPair {
	return &ChartPair{Key: key, Value: value, Time: time}
}
